package com.dm0858.bianmin.mine.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.dm0858.bianmin.R;
import com.dm0858.bianmin.mine.base.BaseRecyclerViewAdapter;
import com.dm0858.bianmin.mine.base.BaseViewHolder;
import com.dm0858.bianmin.mine.bean.MyFavoriteBeanData;

import java.util.List;

public class MyFavoriteRecyclerViewAdapter extends BaseRecyclerViewAdapter {

    private Context mContext;

    private List<MyFavoriteBeanData.DataBean> list;

    /**
     * 构造方法
     *
     * @param mContext
     * @param resource
     * @param data
     */
    public MyFavoriteRecyclerViewAdapter(Context mContext, int resource, List data) {
        super(mContext, resource, data);
        this.mContext = mContext;
        if (data != null) this.list = data;
    }

    @Override
    protected void bindData(BaseViewHolder holder, int position) {
        MyFavoriteBeanData.DataBean data = list.get(position);
        Glide.with(mContext).load(data.getImage()).into(holder.getImageView(R.id.img_picture));
        holder
                .setText(R.id.txt_title,data.getTitle())
                .setText(R.id.txt_area,data.getAddr())
                .setText(R.id.txt_type,data.getSectionName())
                .setText(R.id.txt_date,data.getCreateDate())
                .setOnClickListener(R.id.item, view -> {
                    onItemClick.onClick(data,position);
                });
    }

    @Override
    protected int getSize() {
        if (list == null) return 0;
        else return list.size();
    }

    public void setList(List<MyFavoriteBeanData.DataBean> list) {
        if (list == null) list.clear();
        else this.list = list;
        notifyDataSetChanged();
    }

    public void setOnItemClick(onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public onItemClick onItemClick;


    public interface onItemClick{
        void onClick(MyFavoriteBeanData.DataBean data,int position);
    }
}
